package com.pgybook.front.task;

import freemarker.template.Configuration;
import freemarker.template.Template;
import jodd.util.StringPool;
import org.springframework.core.io.Resource;

import java.io.*;

/**
 * Created with IntelliJ IDEA.
 * User: feeling
 * Date: 13-11-19
 * Time: 下午2:39
 */
public class IndexPageGenerateTask {

    private Resource genPath;
    private Configuration conf;
    private Resource tpl;


    public void doit() throws IOException {
        if(true){
            return;
        }
        long time = System.currentTimeMillis();
        File f = new File("");
        File parent = f.getParentFile();
        if (!parent.exists()) {
            parent.mkdirs();
        }
        Writer out = null;
        try {
            // FileWriter不能指定编码确实是个问题，只能用这个代替了。
            out = new OutputStreamWriter(new FileOutputStream(genPath.getFile()), StringPool.UTF_8);
            Template template = conf.getTemplate(tpl.getFilename());
            Object data=null;
//            template.process(data, out);
        } finally {
            if (out != null) {
                out.flush();
                out.close();
            }
        }
        time = System.currentTimeMillis() - time;
//        log.info("create index page, in {} ms", time);

    }
}
